package com.java.control.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

import com.java.common.SessionInfo;
import com.java.control.AbstractAdminCommandController;
import com.java.control.search.AddressBookSearchCond;
import com.java.control.search.SearchStat;
import com.java.entity.AddressBook;
import com.java.mis.UserType;
import com.java.service.AddressBookService;

/**
 * 人员管理
 * @author wqf
 * @version  Nov 24, 2011 12:00:53 PM
 */
public class AddressBookListController extends AbstractAdminCommandController {

	public AddressBookListController(){
		this.setCommandClass(AddressBookSearchCond.class);
	}	

	protected ModelAndView executeRequest(HttpServletRequest request,HttpServletResponse response,Object command)
		throws Exception{
		ModelAndView mav=new ModelAndView(this.view);
		AddressBookSearchCond searchCond = (AddressBookSearchCond)command;		
		SessionInfo sessionInfo = this.getSessionInfo(request);
		if(null!=sessionInfo){
//			if(sessionInfo.getUserType()!=UserType.admin){
//			    searchCond.setUserId(sessionInfo.getUserId());
//			}
			mav.addObject("userId", sessionInfo.getUserId());
		}		
		searchCond.setPageSize(10L);
		SearchStat searchStat = this.addressBookService.getSearchStat(AddressBook.class, searchCond);
		List<AddressBook> list = this.addressBookService.search(AddressBook.class,searchCond);
		mav.addObject("searchStat", searchStat);
		mav.addObject("searchCond", searchCond);
		mav.addObject("addressBookList", list);	
				
		return mav;
		
	}
		
	private String view;
	private AddressBookService addressBookService;
	
	public void setAddressBookService(AddressBookService addressBookService) {
		this.addressBookService = addressBookService;
	}

	public void setView(String view) {
		this.view = view;
	}

}
